package c_list.example2;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;

import com.alibaba.fastjson.JSON;
import com.wang.template.json.JsonLoader;
import com.wang.template.json.JsonRender;
import com.wang.template.json.node.BaseNode;

public class ListExample1 {
	public static void main(String[] args) throws Exception { 
		BaseNode node = getNode();
		Object data = getData();
		long start = System.currentTimeMillis();
		Object obj = JsonRender.render(node, data);
		System.out.println("耗时" + (System.currentTimeMillis() - start) + JSON.toJSONString(obj, true));

	}


	private static BaseNode getNode() throws Exception {
		String jsonStr = FileUtils.readFileToString(new File(ListExample1.class.getResource("json.json").getPath()),
				"UTF-8");
		return JsonLoader.load(jsonStr);
	}

	private static Object getData() {
		Map<String, Object> dataSource = new HashMap<String, Object>();
		dataSource.put("retCode", "000000");
		dataSource.put("retMsg", "服务执行成功");
		Map<String, String> data = new HashMap<String, String>();
		data.put("goodsId", "000");
		data.put("goodsName", "0商品名称");
		List<Object> list = new ArrayList<Object>();
		list.add(data);
		data = new HashMap<String, String>();
		data.put("goodsId", "111");
		data.put("goodsName", "1商品名称");
		list.add(data);
		dataSource.put("data", list);
		return dataSource;
	}
}
